package com.example.demo.common;

import lombok.Data;

@Data
public class Result<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    // 带数据的成功响应
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    // 新增：无数据的成功响应
    public static Result<?> success() {
        Result<Object> result = new Result<>();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("success");
        return result;
    }

    // 错误响应保持原样
    public static Result<?> error(int code, String message) {
        Result<?> result = new Result<>();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}